#include <algorithm/analytical_model/io/json/converter/shared/data/scene/Receiver.h>
#include <algorithm/analytical_model/io/json/converter/shared/data/topology/geometry/Geometry.h>

using namespace solar;

void solar::tag_invoke(const boost::json::value_from_tag& /*unused*/,
                       boost::json::value& json_value, const Receiver& receiver)
{
    auto geometry_ptr = SOLAR_GET_VALUE(Receiver, geometry_, receiver);
    if (solar::hasValue(geometry_ptr))
    {
        json_value.emplace_object()["geometry"] = boost::json::value_from(geometry_ptr);
    }
}

auto solar::tag_invoke(const boost::json::value_to_tag<Receiver>& /*unused*/,
                       const boost::json::value& json_value) -> Receiver
{
    const auto* value_ptr = json_value.if_object();
    if (value_ptr == nullptr)
    {
        return {};
    }
    Receiver result;
    if (const auto* geometry_value = value_ptr->if_contains("geometry"); geometry_value != nullptr)
    {
        SOLAR_SET_VALUE(Receiver, geometry_,
                        boost::json::value_to<std::shared_ptr<Geometry>>(*geometry_value), result)
    }
    return result;
}
